<#import "/macro.ftl" as m>
<@m.page_header title='后台' />

<div id="page-content-wrapper">

    <div id="page-title">

        <h3>
            产品列表
            <small>
                类资产项目
            </small>
        </h3>
        <div id="breadcrumb-right">
            <div class="float-right">
                <a href="/products/add"" class="btn medium primary-bg">
                    <span class="button-content">
                    <i class="glyph-icon icon-cog float-left"></i>
                    添加
                    </span>
                </a>
            </div>
        </div>
    </div>

<div id="page-content">
    <table class="table" id="exp">
    </table>
</div>

<script language="javascript">
$(document).ready(function() {

    <#if msg!=null>
	$.jGrowl("${msg}", {sticky:!1,position:'bottom-right',theme:'bg-green'});
	</#if>
	function retrieveData( sSource, aoData, fnCallback ) {   
	    aoData.push( { } );   
	    $.ajax( {   
	        "type": "POST",    
	        "contentType": "application/json",   
	        "url": sSource,    
	        "dataType": "json",   
	        "data": JSON.stringify(aoData), //以json格式传递   
	        "success": fnCallback  
	    });   
	}
	
	$(function() {
		$("#exp").dataTable({
			sScrollY: 300,
			bJQueryUI: !0,
			bStateSave: true,
			aaSorting:[[0,'desc']],
			sPaginationType: "full_numbers",
			aoColumns:[
				{'sTitle':'id','mDataProp':'id',"bVisible": false},
				{'sTitle':'serial','mDataProp':'serial',"bVisible": false},
				{'sTitle':'产品名称','mDataProp':'name'},
				{'sTitle':'平台奖励','mDataProp':'bonusRate',"bVisible": false},
				{'sTitle':'年化收益','mDataProp':'interestRate','mRender':function(data, type, full){
					return Math.round(data*10000)/100+'% + '+Math.round(full.bonusRate*10000)/100+'%';
				}},
				{'sTitle':'期限','mDataProp':'term','mRender':function(data, type, full){
					return data+'天';
				}},
				{'sTitle':'起售金额','mDataProp':'minAmount','mRender':function(data, type, full){
					return data+'元';
				}},
				{'sTitle':'起售日期','mDataProp':'startTime','mRender':function(data, type, full){
					return  new Date(data).Format("yyyy-MM-dd");
				}},
				{'sTitle':'产品状态','mDataProp':'status','mRender':function(data, type, full){
					return full.statusValue;
				}},
				{'sTitle':'操作','bSortable':false,'mRender':function(data, type, full){
					var html='<div class="dropdown">';
		            html+='<a href="javascript:;" title="" class="btn medium bg-blue" data-toggle="dropdown">';
		            html+='<span class="button-content">';
		            html+='<i class="glyph-icon font-size-11 icon-cog"></i>';
		            html+='<i class="glyph-icon font-size-11 icon-chevron-down"></i>';
		            html+='</span>';
		            html+='</a>';
		            html+='<ul class="dropdown-menu float-right">';
		            html+='<li><a href="/products/update/'+full.serial+'" title=""><i class="glyph-icon icon-edit mrg5R"></i>修改</a></li>';
		            if(full.status=="EDITING"){
		            html+='<li><a href="javascript:;" id="pub_'+full.serial+'" class="pub" title=""><i class="glyph-icon icon-calendar mrg5R"></i>上架</a></li>';
		            html+='<li><a href="javascript:;" id="time_pub_'+full.serial+'" class="time-pub" title=""><i class="glyph-icon icon-calendar mrg5R"></i>到点上架</a></li>';
		            }else{
		            html+='<li><a href="javascript:;" id="dow_'+full.serial+'" class="dow" title=""><i class="glyph-icon icon-calendar mrg5R"></i>下架</a></li>';
		            }
		            html+='<li><a href="/stat/stat/'+full.serial+'" title=""><i class="glyph-icon icon-download mrg5R"></i>统计</a></li>';
		            html+='<li class="divider"></li>';
		            html+='<li><a href="javascript:;" id="del_'+full.serial+'" class="font-red del" title=""><i class="glyph-icon icon-remove mrg5R"></i>删除</a> </li>';
		            html+='';
		            html+='';
		            html+='';
		            html+='</ul>';
		            html+='</div>';
					return html;
				}},
			],
			"bServerSide": true,
			"sAjaxSource": "list/ajax",
			"fnServerData": retrieveData,
			"oLanguage":{
				"sInfoEmpty": "没有数据",
				"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
				"sZeroRecords": "没有检索到数据",
				"oPaginate":{
					"sFirst": "首页",
					"sPrevious": "前页",
					"sNext": "后页",
					"sLast": "尾页"
				}
			},
			
			"fnDrawCallback":function(){
				$(".del").click(function(a) {
					$.messager.confirm("", "是否确认删除该产品？", function() { 
				        location.href="/products/delete/"+a.delegateTarget.id.substring(4);
				    });
				});
				$(".pub").click(function(a) {
					$.messager.confirm("", "是否确认上架该产品？", function() { 
				        location.href="/products/publish/"+a.delegateTarget.id.substring(4);
				    });
				});
				$(".dow").click(function(a) {
					$.messager.confirm("", "是否确认下架该产品？", function() { 
				        location.href="/products/publish/"+a.delegateTarget.id.substring(4);
				    });
				});
				$(".time-pub").click(function(a) {
					$.messager.confirm("", "是否确认到点上架该产品？", function() { 
				        location.href="/products/timepublish/"+a.delegateTarget.id.substring(9);
				    });
				});
			},
			
			"bRetrieve":true,
			"aoColumnDefs": [{
				sDefaultContent: '',
				aTargets: [ '_all' ]
			}]
			
		})
	})
	$(document).on("scroll",".dataTables_scrollBody",function(){$(".dataTables_scrollBody").css({"overflow":"visible","height":"100%"})})
	
});

</script>
